package com.java.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.java.system.entity.Camera;
import com.java.system.entity.Type;
import com.java.system.mapper.TypeMapper;
import com.java.system.service.ITypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xiaoman
 * @since 2023-07-12
 */
@Service
public class TypeServiceImpl extends ServiceImpl<TypeMapper, Type> implements ITypeService {
    @Autowired
    TypeMapper typeMapper;

    @Override
    public List<Type> getType() {
        LambdaQueryWrapper<Type> queryWrapper=new LambdaQueryWrapper<>();
        List<Type> typeList = typeMapper.selectList(queryWrapper);
        if(StringUtils.isEmpty(typeList)){
            return null;
        }
        else {
            return typeList;
        }
    }

    @Override
    public List<Camera> getCameraListById(Integer id) {
        List<Camera> cameraList = typeMapper.getCameraListById(id);
        if(!StringUtils.isEmpty(cameraList)){
            return cameraList;
        }
        else {
            return null;
        }
    }

    @Override
    public void insertType(Type type) {
        typeMapper.insert(type);
    }

    @Override
    public Type getTypeById(Integer id) {
        Type type = typeMapper.selectById(id);
        if(type!=null){
            return type;
        }
        else {
            return null;
        }
    }

    @Override
    public void updateType(Type type) {
        typeMapper.updateById(type);
    }

    @Override
    public void deleteType(Integer id) {
        typeMapper.deleteById(id);
    }
}
